<?php
abstract class BaseController {
	
	var $SYSTEM_ERROR = '/error/systemerr.php';

	private $header;
	private $footer;
	
	const AUTHENTICATION_REQUIRED = true;
	const AUTHENTICATION_NOTREQUIRED = false;

	public function BaseController($auth = false) {
		// i was thinking I could use this to 
		// automatically invoke a unit test from the URL.
		// TODO - figure out how to automatically test my controllers with out routing.
		if (getParameter("unit_test") == "true"){
			$this->test();
			exit();
		}

		if ($auth) { // if auth required
		    if (SecurityManager::is_authenticated() == false) { // if not logged in
		        $this->render('/admin/login');
		        exit();
		    }
		}
	}

	public function setHeader($header) {
	    $this->header = $header;
	}

	public function setFooter($footer) {
	    $this->footer = $footer;
	}

	public function render($view, $data=null) {
		// extracts the associative array put in data to actual variables for the page/view
		//if ($data != null) extract($data);
		$full_file = WEB_ROOT.'/app/views/'.$view.'.php';
		if (file_exists($full_file)) {
			// extracts the associative array put in data to actual variables for the page/view
			if ($data != null) extract($data);
			//include $this->header;
			include $full_file;
			//include $this->footer;
		} else {
			include WEB_ROOT.'/error/404.php';
		}
	}

	abstract function test();
}
?>